/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.sapra.Prefactura;



import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.sapra.dep.conexion.DBWRAP;


/**
 *
 * @author ppratsc
 */
public class wDeducciones extends nextapp.echo2.app.WindowPane {
    private String m_nombre;
    private int m_partida=0;
    private DBWRAP pdb;

    public wDeducciones(DBWRAP db,int part,String name) {
        super();
        m_nombre = name;
        m_partida = part;
        pdb = db;
        this.setTitle(name);
        this.setClosable(false);
        add(new DeducWindowContentPane());
    }

    private class DeducWindowContentPane extends nextapp.echo2.app.ContentPane{

        public DeducWindowContentPane() {
            super();
            initComponents();
        }

        // <editor-fold defaultstate="collapsed" desc="Generated Code">
        private void initComponents() {

            column1 = new nextapp.echo2.app.Column();//GEN-BEGIN:init_components
            label2 = new nextapp.echo2.app.Label();
            textField3 = new nextapp.echo2.app.TextField();
            button4 = new nextapp.echo2.app.Button();

            add(column1);

            column1.add(label2);
            column1.add(textField3);
            column1.add(button4);

            label2.setFont(new nextapp.echo2.app.Font(
                    nextapp.echo2.app.Font.SANS_SERIF,
                    nextapp.echo2.app.Font.PLAIN,
                    new nextapp.echo2.app.Extent(13, nextapp.echo2.app.Extent.PX)));

            label2.setForeground(new nextapp.echo2.app.Color(
                    0x0004ff));

            label2.setText("Costo de Reposicion de Tarjeta:");


            textField3.setBackground(nextapp.echo2.app.Color.LIGHTGRAY);

            textField3.setText("60.00");


            button4.setStyleName("Default");

            button4.setText("OK");

            button4.addActionListener(new nextapp.echo2.app.event.ActionListener(){
                public void actionPerformed(nextapp.echo2.app.event.ActionEvent evt) {
                    btguardar(evt);
                }
            });//GEN-END:init_components

            loadInitialData();
        }// </editor-fold>


        // Action listeners//GEN-LINE:listeners_area

        private void btguardar(nextapp.echo2.app.event.ActionEvent evt) {//GEN-FIRST:btguardar_nextapp.echo2.app.event.ActionEvent
            String sql = "UPDATE facturapartida SET reposicion =";
            double deduccion = Double.parseDouble(textField3.getText());
            if(deduccion > 0)deduccion = deduccion * -1;
            sql += deduccion;
            sql += " where partidaid="+m_partida;
            try {
                pdb.update(sql);
            } catch (SQLException ex) {
                Logger.getLogger(wDeducciones.class.getName()).log(Level.SEVERE, null, ex);
            }
            wDeducciones win = (wDeducciones)getParent();
            win.userClose();
        }//GEN-LAST:btguardar_nextapp.echo2.app.event.ActionEvent



        // Variables declaration - do not modify//GEN-BEGIN:variables_declaration
        private nextapp.echo2.app.Column column1;
        private nextapp.echo2.app.Label label2;
        private nextapp.echo2.app.TextField textField3;
        private nextapp.echo2.app.Button button4;//GEN-END:variables_declaration

        private void loadInitialData() {
            String sql = "select reposicion from facturapartida where partidaid="+m_partida;
            ResultSet rs;
            try {
                rs = pdb.select(sql);
                if(rs.next()){
                    textField3.setText(rs.getString("reposicion"));
                }
            } catch (SQLException ex) {
                Logger.getLogger(wDeducciones.class.getName()).log(Level.SEVERE, null, ex);
            }

        }

    }
}
